package Engine.Movie
{
	import flash.display.BitmapData;

	public class PngMovie
	{
		
		private var _pngList:Array = new Array();
		private var _currentFrame:int;
		private var _compuleteFun:Function = null;
		private var _compuleteArg:Object = null;
		
		private var _width:Number;
		private var _height:Number;
		
		
		public function PngMovie()
		{
			this._currentFrame = 0;		
		}
		
		public function nextFrame():BitmapData
		{
			var bt:BitmapData = this._pngList[this._currentFrame];
			if(this._currentFrame - 1 >= this._pngList.length)
			{
				this._currentFrame = 0;	
				if(this._compuleteFun != null)
					this._compuleteFun(this._compuleteArg);
			}
			else
			{
				this._currentFrame++;
			}
			return bt;
		}
		
		public function setCompuleteFun(fun:Function,arg:Object = null):void
		{
			this._compuleteFun = fun;
			this._compuleteArg = arg;
		}
		
		public function setPngArray(ar:Array):void
		{
			this.clear();
			this._pngList = ar;
		}
		
		private function clear():void
		{
			while(this._pngList.length)
			{
				var bt:BitmapData = this._pngList.shift();
				bt.dispose();
			}
			this._currentFrame = 0;
		}
		
		public function stop():void
		{
			this._currentFrame = 0;
		}
		
		public function setSize(w:Number,h:Number):void
		{
			this._width = w;
			this._height = h;
		}
		
		public function get width():Number
		{
			return this._width;
		}
		
		public function get height():Number
		{
			return this._height;
		}
		
		public function get movieArg():Object
		{
			return this._compuleteArg;
		}
		
	}
}